<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>user-detail</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body style="text-align: left">
    <form style="margin: 0 auto 0 300px" method="post" action="/user/updateUser">
        <input type="hidden" name="id" th:attr="value=${user.id}">
        用户名：<input type="text" name="username" th:attr="value=${user.username}"><br>
        性别：<select name="sex">
            <option value="0" th:attr="selected=${user.sex ==0 }">未填</option>
            <option value="1" th:attr="selected=${user.sex ==1 }">男</option>
            <option value="2" th:attr="selected=${user.sex ==2 }">女</option>
        </select><br>
        年龄：<input type="number" name="age" th:attr="value=${user.age}"><br>
        更新次数:<span th:text="${user.updateCount}"></span>
        <input type="hidden" name="version" th:attr="value=${user.version}"><br>
        <button type="submit">提交</button>
    </form>

    <script>
        $(function(){
            $(document).on("click","button[name=del]",function () {
                var userId = $(this).attr("userId");
                $.get("/user/delUser?userId="+userId,function (reps) {
                    if(reps.status ==1){
                        location.reload();
                    }
                })
            })

            $(document).on("click","button[name=update]",function () {
                var userId = $(this).attr("userId");
                location.href="/user/userDetail?userId="+userId;
            })
        });
    </script>
</body>
</html>